snapshot: Add API for colors and textures
authorBenjamin Otte <otte@redhat.com>
Tue, 13 Dec 2016 03:22:13 +0000 (04:22 +0100)
committerBenjamin Otte <otte@redhat.com>
Tue, 20 Dec 2016 17:01:10 +0000 (18:01 +0100)
docs/reference/gtk/gtk4-sections.txt
gtk/gtkrendericon.c
gtk/gtksnapshot.c
gtk/gtksnapshot.h

index 191363ae5dc9e36ef40e58061abe56250b3736a6..4882717c797b56e4aef379182459c70317a93662 100644 (file)
@@ -4462,6 +4462,8 @@ gtk_snapshot_transform
 gtk_snapshot_translate_2d
 gtk_snapshot_append_node
 gtk_snapshot_append_cairo_node
+gtk_snapshot_append_texture_node
+gtk_snapshot_append_color_node
 gtk_snapshot_clips_rect
 gtk_snapshot_render_background
 gtk_snapshot_render_frame
index 082f87d7d2702a14bbcb26685839bb6cfa9ec681..9be7201e83a7c5db4b2bb72ee61056216e0a4573 100644 (file)
@@ -297,17 +297,11 @@ gtk_css_style_snapshot_icon_texture (GtkCssStyle *style,
 
   if (graphene_matrix_is_identity (&transform_matrix))
     {
-      double offset_x, offset_y;
-
-      gtk_snapshot_get_offset (snapshot, &offset_x, &offset_y);
       graphene_rect_init (&bounds,
-                          offset_x, offset_y,
+                          0, 0,
                           gsk_texture_get_width (texture) / texture_scale,
                           gsk_texture_get_height (texture) / texture_scale);
-      icon_node = gsk_texture_node_new (texture, &bounds);
-      gsk_render_node_set_name (icon_node, "Icon");
-      
-      gtk_snapshot_append_node (snapshot, icon_node);
+      gtk_snapshot_append_texture_node (snapshot, texture, &bounds, "Icon");
     }
   else
     {
index ff0eda2dd7a1de8a77c2421471ee1e1deb6f641b..9ba07a5c4c55f1830d90add2200b6ef3245e4860 100644 (file)
@@ -374,6 +374,100 @@ gtk_snapshot_append_cairo_node (GtkSnapshot           *snapshot,
   return cr;
 }
 
+/**
+ * gtk_snapshot_append_texture_node:
+ * @snapshot: a #GtkSnapshot
+ * @texture: the #GskTexture to render
+ * @bounds: the bounds for the new node
+ * @name: (transfer none): a printf() style format string for the name for the new node
+ * @...: arguments to insert into the format string
+ *
+ * Creates a new render node drawing the @texture into the given @bounds and appends it
+ * to the current render node of @snapshot.
+ **/
+void
+gtk_snapshot_append_texture_node (GtkSnapshot            *snapshot,
+                                  GskTexture             *texture,
+                                  const graphene_rect_t  *bounds,
+                                  const char             *name,
+                                  ...)
+{
+  GskRenderNode *node;
+  graphene_rect_t real_bounds;
+
+  g_return_if_fail (snapshot != NULL);
+  g_return_if_fail (GSK_IS_TEXTURE (texture));
+  g_return_if_fail (bounds != NULL);
+
+  graphene_rect_offset_r (bounds, snapshot->state->translate_x, snapshot->state->translate_y, &real_bounds);
+  node = gsk_texture_node_new (texture, &real_bounds);
+
+  if (name)
+    {
+      va_list args;
+      char *str;
+
+      va_start (args, name);
+      str = g_strdup_vprintf (name, args);
+      va_end (args);
+
+      gsk_render_node_set_name (node, str);
+
+      g_free (str);
+    }
+
+  gtk_snapshot_append_node (snapshot, node);
+  gsk_render_node_unref (node);
+}
+
+/**
+ * gtk_snapshot_append_color_node:
+ * @snapshot: a #GtkSnapshot
+ * @color: the #GdkRGBA to draw
+ * @bounds: the bounds for the new node
+ * @name: (transfer none): a printf() style format string for the name for the new node
+ * @...: arguments to insert into the format string
+ *
+ * Creates a new render node drawing the @color into the given @bounds and appends it
+ * to the current render node of @snapshot.
+ *
+ * You should try to avoid calling this function if @color is transparent.
+ **/
+void
+gtk_snapshot_append_color_node (GtkSnapshot           *snapshot,
+                                const GdkRGBA         *color,
+                                const graphene_rect_t *bounds,
+                                const char            *name,
+                                ...)
+{
+  GskRenderNode *node;
+  graphene_rect_t real_bounds;
+
+  g_return_if_fail (snapshot != NULL);
+  g_return_if_fail (color != NULL);
+  g_return_if_fail (bounds != NULL);
+
+  graphene_rect_offset_r (bounds, snapshot->state->translate_x, snapshot->state->translate_y, &real_bounds);
+  node = gsk_color_node_new (color, &real_bounds);
+
+  if (name)
+    {
+      va_list args;
+      char *str;
+
+      va_start (args, name);
+      str = g_strdup_vprintf (name, args);
+      va_end (args);
+
+      gsk_render_node_set_name (node, str);
+
+      g_free (str);
+    }
+
+  gtk_snapshot_append_node (snapshot, node);
+  gsk_render_node_unref (node);
+}
+
 static void
 rectangle_init_from_graphene (cairo_rectangle_int_t *cairo,
                               const graphene_rect_t *graphene)
index 2c6253340021faf0026619aaf4035a8250fe638c..8a2cc4ac1ea9e2e4314b71b88269195f7c4199f0 100644 (file)
@@ -64,6 +64,18 @@ cairo_t *       gtk_snapshot_append_cairo_node          (GtkSnapshot
                                                          const graphene_rect_t  *bounds,
                                                          const char             *name,
                                                          ...) G_GNUC_PRINTF(3, 4);
+GDK_AVAILABLE_IN_3_90
+void            gtk_snapshot_append_texture_node        (GtkSnapshot            *snapshot,
+                                                         GskTexture             *texture,
+                                                         const graphene_rect_t  *bounds,
+                                                         const char             *name,
+                                                         ...) G_GNUC_PRINTF (4, 5);
+GDK_AVAILABLE_IN_3_90
+void            gtk_snapshot_append_color_node          (GtkSnapshot            *snapshot,
+                                                         const GdkRGBA          *color,
+                                                         const graphene_rect_t  *bounds,
+                                                         const char             *name,
+                                                         ...) G_GNUC_PRINTF (4, 5);
 
 GDK_AVAILABLE_IN_3_90
 gboolean        gtk_snapshot_clips_rect                 (GtkSnapshot            *snapshot,